<%@ page language="java" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>企业信息管理系统_用户登录</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<link rel="stylesheet" type="text/css" href="resources/css/login.css">
		<script type="text/javascript" src="resources/javascript/jquery.js"></script>
		<script type="text/javascript" src="resources/javascript/util.js"></script>
		<script type="text/javascript">
		
		
		document.onkeydown = function(e) {
			var ieKey = (document.all) ? window.event : e;
			var eventCode = (document.all) ? ieKey.keyCode : ieKey.which;
			var srcElement = (document.all) ? ieKey.srcElement : ieKey.target;
			if ((eventCode == 8 && ((srcElement.type != "textarea" && srcElement.type != "text" && srcElement.type != "password") || srcElement.readOnly))) { // 禁用后退键
				return false;
			}
			return true;
		}
		
		$(function() {
			var inputs = $("input");
			var i = 0;
			for (var i = 0; i < inputs.length; i++) {
				var input = inputs[i];
				var type = input.type;
				if (type == "text" || type == "password") {
					initKeyDown($(input));
				}
			}
		});
		
		function initKeyDown(input) {
			input.keydown(function(e) {
				var ieKey = (document.all) ? window.event : e;
				var eventCode = (document.all) ? ieKey.keyCode : ieKey.which;
				if (eventCode == 13) {
					doLogin();
				}
			});
		}
		
		/**
		 * 用户登录
		 */
		function doLogin() {
			if (validateLogin()) {
				var username = $("#username").attr("value");
				var password = $("#password").attr("value");
				var validCode = $("#validCode").attr("value");
				var url = "login.do";
				var params = {
					"username" : username,
					"password" : password,
					"validCode" : validCode
				};
				$.post(url, params, function(data, status) {
					
				}, "json");
			}
		}
		
		/**
		 * 验证用户登录
		 */
		function validateLogin() {
			var username = $("#username");
			var password = $("#password");
			var validCode = $("#validCode");
			return validate(username, "用户名不能为空!")
				&& validate(username, "用户名长度不合法!", 4)
				&& validate(password, "用户密码不能为空!")
				&& validate(validCode, "验证码不能为空!")
				&& validate(validCode, "验证码长度不合法!", 4);
		}
		
		/**
		 * 验证
		 */
		function validate(input, message, minLength) {
			var value = input.attr("value");
			if (minLength) {
				if (value == null || $.trim(value).length < minLength) {
					alert(message);
					input.setFocus();
					return false;
				}
			}
			if (value == null || $.trim(value).length == 0) {
				alert(message);
				input.setFocus();
				return false;
			}
			return true;
		}
		
		/**
		 * 显示验证码
		 */
		function show(imgObj) {
			if (imgObj) {
				imgObj.src = "validateCode.do?random=" + Math.random();
			}
		}
	</script>
	</head>

	<body
		style="background-repeat: no-repeat; background-color: #9CDCF9; background-position: 0px 0px;">
		<div id="temp"></div>
		<table width="681" border="0" align="center" cellpadding="0"
			cellspacing="0" style="margin-top: 120px">
			<tr>
				<td width="353" height="259" align="center" valign="bottom"
					background="resources/images/login/1.gif">
					<table width="90%" border="0" cellspacing="3" cellpadding="0">
						<tr>
							<td align="right" valign="bottom" style="color: #05B8E4">
								Power by
								<a href="#" target="_blank">落羽社区</a> Copyright 2010
							</td>
						</tr>
					</table>
				</td>
				<td width="195" background="resources/images/login/2.gif">
					<table width="190" height="106" border="0" align="center"
						cellpadding="2" cellspacing="0">
						<tr>
							<td height="50" colspan="2" align="left">
								&nbsp;
							</td>
						</tr>
						<tr>
							<td width="60" height="30" align="left">
								用&nbsp;户&nbsp;名
							</td>
							<td>
								<input name="username" type="text"
									style="background: url(resources/images/login/6.gif) repeat-x; border: solid 1px #27B3FE; height: 20px; width: 120px; background-color: #FFFFFF"
									id="username" size="16">
							</td>
						</tr>
						<tr>
							<td height="30" align="left">
								用户密码
							</td>
							<td>
								<input name="password" type="password"
									style="background: url(resources/images/login/6.gif) repeat-x; border: solid 1px #27B3FE; height: 20px; width: 120px; background-color: #FFFFFF"
									id="password" size="16">
							</td>
						</tr>
						<tr>
							<td height="30">
								验&nbsp;证&nbsp;码
							</td>
							<td>
								<input name="validCode" type="text" id="validCode" size="4"
									style="background: url(resources/images/login/6.gif) repeat-x; border: solid 1px #27B3FE; height: 20px; width: 60px; background-color: #FFFFFF"
									maxlength="4">
								<img src="validateCode.do" alt="看不清点击刷新" align="absmiddle"
									onclick="javascript:show(this)" width="55" height="20" />
							</td>
						</tr>
						<tr>
							<td height="40" colspan="2" align="center">
								<img src="resources/images/login/tip.gif" width="16" height="16">
								请勿非法登陆！
							</td>
						<tr>
							<td colspan="2" align="center">
								<input type="submit" name="submit" onclick="javascript:doLogin();"
									style="background: url(resources/images/login/5.gif) no-repeat"
									value=" 登  陆 ">
								<input type="reset" name="submit"
									style="background: url(resources/images/login/5.gif) no-repeat"
									value=" 取  消 ">
							</td>
						<tr>
							<td height="5" colspan="2"></td>
					</table>
				</td>
				<td width="133" background="resources/images/login/3.gif">
					&nbsp;
				</td>
			</tr>
			<tr>
				<td height="161" colspan="3"
					background="resources/images/login/4.gif"></td>
			</tr>
		</table>
	</body>
</html>
